package com.qxzn.module.home.adapter;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.qxzn.app.bean.UserRemindBean;
import com.qxzn.app.util.DateUtil;
import com.qxzn.module.home.R;
import com.qxzn.module.home.R2;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class UserRemindListAdapter extends RecyclerView.Adapter<UserRemindListAdapter.ViewHolder> {

    private Activity activity;
    private List<UserRemindBean> dataList;
    private UserRemindBean item;

    public UserRemindListAdapter(Activity activity, List dataList) {
        this.activity = activity;
        this.dataList = dataList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(activity).inflate(R.layout.item_user_remind, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        item = dataList.get(position);
//        holder.tvApm.setText(item.getMemName());
        holder.tvTime.setText(item.getMedicinetime());
        if (item.getType() == 0) {
            if (TextUtils.isEmpty(item.getTitle())) {
                holder.tvContent.setText("每天");
            } else {
                holder.tvContent.setText(item.getTitle() + "，每天");
            }
        } else if (item.getType() == 1) {
            if (TextUtils.isEmpty(item.getTitle())) {
                holder.tvContent.setText(DateUtil.getWeekStrByWeekNum(item.getTypevalue(), "周"));
            } else {
                holder.tvContent.setText(item.getTitle() + "，" + DateUtil.getWeekStrByWeekNum(item.getTypevalue(), "周"));
            }
        } else if (item.getType() == 2) {
            if (TextUtils.isEmpty(item.getTitle())) {
                holder.tvContent.setText("每隔" + item.getTypevalue());
            } else {
                holder.tvContent.setText(item.getTitle() + "，每隔" + item.getTypevalue());
            }
        } else if (item.getType() == 3) {
            if (TextUtils.isEmpty(item.getTitle())) {
                holder.tvContent.setText("只响一次");
            } else {
                holder.tvContent.setText(item.getTitle() + "，只响一次");
            }
        }
//        Glide.with(activity).load(item.getHeadportrait()).apply(RequestOptions.bitmapTransform(new CircleCrop()).placeholder(R.mipmap.logo).error(R.mipmap.logo)).into(holder.ivIcon);
    }

    @Override
    public int getItemCount() {
        return dataList == null ? 0 : dataList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R2.id.tv_apm)
        TextView tvApm;
        @BindView(R2.id.tv_time)
        TextView tvTime;
        @BindView(R2.id.tv_content)
        TextView tvContent;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
